package org.groupg.filetodb;

import cn.hutool.core.date.TimeInterval;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;

public class FileToDB {
    static final File file = new File("E:\\Develop\\demo001-4kw.csv");

    public static void main(String[] args) throws IOException {

        TimeInterval timeInterval = new TimeInterval();
        timeInterval.start();
        try (Reader reader = Files.newBufferedReader(file.toPath());
             CSVParser parser = new CSVParser(reader, CSVFormat.DEFAULT)) {

            while (parser.iterator().hasNext()) {
                CSVRecord record = parser.iterator().next();
                System.out.println(record);
            }
        }
        try (CSVReader reader = new CSVReader(new FileReader(file))) {
            String[] nextLine;
            while ((nextLine = reader.readNext()) != null) {
                // 处理每一行数据
                for (String cell : nextLine) {
                    System.out.print(cell + " ");
                }
                System.out.println();
            }
        } catch (IOException | CsvValidationException e) {
            e.printStackTrace();
        }
        long interval = timeInterval.interval();
        System.out.println(interval);

    }
}
